// pages/zhuye/zhuye.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */

  data: {
    show_a:'',
    phone:'',
    jiami: '',
    OPEN_ID:'',
    session_key: '',
    Getphone:true,
  },

    /**
   * 图片点击跳转
   */


  yananyulin(){
    wx.showToast({
      title: '此区域暂无活动',
      duration: 1000
    })
  },

   //渭南员工
  weinanyuan(){
    wx.navigateTo({
      url: '../../pages/weinanyuangongdenglu/weinanyuangongdenglu'
    })
  },







//西安员工
  xianyuan:function(){
    wx.navigateTo({
      url: '../../pages/xianyuangongdenglu/xianyuangongdenglu'
    })
  },

//汉中员工登录
huanzhong:function(){
  wx.navigateTo({
    url: '../../pages/hanzhongyuangongdeng/hanzhongyuangongdeng'
  })
},



      
//安康员工登录
  user_ak:function(){
    wx.navigateTo({
      url: '../../pages/akyuanlong/akyuanlong'
      
    })
  },

   
//商洛员工登录
  user_c:function(){
    wx.navigateTo({
      url: '../../pages/shangyuan/shangyuan'
      
    })
  },




//省公司登录
  user:function(){
    wx.navigateTo({
      url: '../../pages/login/login'
    })
  },

  //宝鸡员工登录
  user_bj:function(){
    wx.navigateTo({
      url: '../../pages/bjygdenglu/bjygdenglu'
    })
  },



  //抽取代金券
// user_b:function(){
//     wx.navigateTo({
//       url: '../../pages/jqlogin/jqlogin'
//     })
//   },

  //商洛大抽奖
  user_e:function(){
    wx.navigateTo({
      url: '../../pages/yinliushuju/yinliushuju'
    })
  },

  //咸阳登录
  user_xy:function(){
    wx.navigateTo({
      url: '../../pages/xyyuanlogin/xyyuanlogin'
    })
  },

//铜川登陆
  user_tc:function(){
    wx.navigateTo({
      url: '../../pages/tcyuanlogin/tcyuanlogin'
    })
  },

  shang_hj:function(){
    wx.navigateTo({
      url: '../../pages/shanghjzc/shanghjzc'
    })
  },

  //获取手机号
  getPhoneNumber(e) {
    console.log(e);
    // console.log(e.detail.code)
    this.setData({
      code: e.detail.code
    })
    wx.request({ 
      url: app.globalData.interface+'/post/API_1032_getWeiXinPhone',
      method: 'GET',
      //向后端发送的数据
      data: {
        code: this.data.code  //将code发送到后台服务器。
      },  
      header: {
        "Content-Type": "application/x-www-form-urlencoded"  //POST方式是这个
      },
      success:res => { 
        console.log(res);
        console.log(res.data.phone);
        if (res.data.result != 'success') {
          wx.showToast({
            title: '获取手机号失败',
            duration: 1000
          })
        } else {
          this.setData({
            phone:res.data.phone,
            Getphone: true,
          })
          this.baocunphone()//保存手机号接口

  
        }
      }
    })
  },

  baocunphone() {
    wx.request({ 
      url: app.globalData.interface+'/newVersion/API_2011_savePhoneAndOpenId',
      method: 'POST',
      //向后端发送的数据
      data: {
        CUSTOMER_TEL:this.data.phone,
   
        KEY:'xianjgjKey9999',
        OPEN_UUID: this.data.jiami,
        OPEN_ID:this.data.openid,
        session_key: this.data.session_key,
      },  
      header: {
        "Content-Type": "application/x-www-form-urlencoded"  //POST方式是这个
      },
      success:res => { 
        console.log(res);
      }
    })

  },



 
  // 判断是否授权
  // scanCod() {
  //   var that = this
  //   wx.request({ 
  //   url: app.globalData.interface+'/newVersion/API_2007_getPhoneByOpenId',
  //   method: 'POST',
  //   //向后端发送的数据
  //   data: {
  //     OPEN_ID:this.data.openid  //将code发送到后台服务器。
  //   },  
  //   header: {
  //     "Content-Type": "application/x-www-form-urlencoded"  //POST方式是这个
  //   },
  //   success:res => { 
  //     console.log(res);
  //     console.log(res.data.data.CUSTOMER_TEL);
  //     if (res.data.result != 'success') {
  //       wx.showToast({
  //         title: '请获取手机号',
  //         duration: 1000
  //       })
  //       that.setData({

  //         Getphone: false,
  //       })
        
  //     } else {
  //       that.setData({
  //         LEVEL_IMG:res.data.data.LEVEL_IMG,
  //         CUSTOMER_TEL:res.data.data.CUSTOMER_TEL,
  //         Getphone: true,
  //       })
        
  //     }
  //   }
  // })
  // },


  


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

    var that = this


    that.setData({
      phone: app.globalData.phone,

      openid: app.globalData.openid,
      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,
    });

    




  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {


    setTimeout(() => {
      this.setData({
        phone: app.globalData.phone,
  
        openid: app.globalData.openid,
        jiami: app.globalData.jiami,
        OPEN_ID: app.globalData.openid,
        session_key: app.globalData.session_key,
      });
  
      console.log(this.data.phone);


      var that = this
  
      if (that.data.phone == '') {
  
        wx.login({
          success: function (res) {
            console.log(res);
            if (res.code) {  //wx.login获取code。
              console.log(res.code);
              //发起网络请求
              wx.request({
                url: app.globalData.interface+'/post/API_1062_appGetOpenid',
                method: 'GET',
                //向后端发送的数据
                data: {
                  code: res.code  //将code发送到后台服务器。
                },
                header: {
                  "Content-Type": "application/x-www-form-urlencoded" //POST方式是这个
                },
                success: res => {
                  console.log(res);
                  console.log(res.data.openid);
                  let openid = res.data.openid;
                  app.globalData.openid = openid;
                  that.setData({
                    openid: res.data.openid
                  })
                  // that.scanCod()
                }
              })
            } else {
              console.log('获取用户登录态失败！' + res.errMsg)
            }
          }
        });
        
      }else{

        console.log('已获取');
      }
    },1000)








    wx.request({
      url: app.globalData.interface+'/shanyouhui/API_1010_getOneConfig?code=LOOKBANNER',
      method: 'GET',
  
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res.data.configList);

        this.setData({
          show_a:res.data.configList//on
        })
      }
    })



    



  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }

})

